package com.example.java.designpattern.builder;

import com.example.java.designpattern.DelegateDivisor;
import com.example.java.designpattern.Divisor;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author zengty
 * @apiNote 委派建造者
 * @date 2024/8/29
 * @project study
 */
public class DelegateDivisorBuilder implements DivisorBuilder {

    private final Collection<Divisor> divisors;

    public DelegateDivisorBuilder(){
        this.divisors = new ArrayList<>();
    }

    public DelegateDivisorBuilder(Collection<Divisor> divisors){
        this.divisors = divisors;
    }

    public DelegateDivisorBuilder addDivisor(Divisor divisor){
        divisors.add(divisor);
        return this;
    }

    public static DelegateDivisorBuilder withDivisors(Collection<Divisor> divisors){
        return new DelegateDivisorBuilder(divisors);
    }

    @Override
    public DelegateDivisor build(){
        return new DelegateDivisor(divisors);
    }
}
